<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">
  
  

  
  
  
  
  
  
  <title>Suwen</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta property="og:type" content="website">
<meta property="og:title" content="Suwen">
<meta property="og:url" content="http://yoursite.com/page/2/index.html">
<meta property="og:site_name" content="Suwen">
<meta property="og:locale" content="CHS">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Suwen">
  
  
    <link rel="icon" href="/css/images/favicon.ico">
  
  <link rel="stylesheet" href="/css/style.css">
  

  
  <!-- baidu webmaster push -->
  <script src="//push.zhanzhang.baidu.com/push.js"></script>
</head></html>
<body class="home blog custom-background custom-font-enabled single-author">
  <div id="page" class="hfeed site">
      <header id="masthead" class="site-header" role="banner">
    <hgroup>
      <h1 class="site-title">
        <a href="/" title="Suwen" rel="home">Suwen</a>
      </h1>
      
        <h2 class="site-description">
          <a href="/" id="subtitle">never settle</a>
        </h2>
      
    </hgroup>

    <nav id="site-navigation" class="main-navigation" role="navigation">
            <button class="menu-toggle">菜单</button>
            <a class="assistive-text" href="/#content" title="跳至内容">跳至内容</a><!--TODO-->
            <div class="menu-main-container">
                <ul id="menu-main" class="nav-menu">
                
                    <li class="menu-item menu-item-type-post_type menu-item-object-page"><a href="/">Home</a></li>
                
                    <li class="menu-item menu-item-type-post_type menu-item-object-page"><a href="/archives">Archives</a></li>
                
                    <li class="menu-item menu-item-type-post_type menu-item-object-page"><a href="/shigure">Shigure</a></li>
                
                </ul>
            </div>
    </nav>
</header>

      <div id="main" class="wrapper">
        <div id="primary" class="site-content"><div id="content" role="main">
  
    <article id="post-Java-Login" class="post-Java-Login post type-post status-publish format-standard hentry">
    <!---->

      <header class="entry-header">
        
        
  
    <h1 class="entry-title">
      <a class="article-title" href="/2019/06/03/Java-Login/">JavaWeb MySQL 实现登录验证</a>
    </h1>
  

        
        <div class="comments-link">
            
            <a href="javascript:void(0);" data-url="http://yoursite.com/2019/06/03/Java-Login/" data-id="ck2tq8ur90005sj77ua7344kd" class="leave-reply bdsharebuttonbox" data-cmd="more">Share</a>
        </div><!-- .comments-link -->
      </header><!-- .entry-header -->

    <div class="entry-content">
      
        <h1 id="0-环境准备"><a href="#0-环境准备" class="headerlink" title="0.环境准备"></a>0.环境准备</h1><p>项目创建：</p>
<blockquote>
<p>IDEA 创建 Servlet 项目详细步骤:<a href="https://www.jianshu.com/p/386a79d16e05" target="_blank" rel="noopener">https://www.jianshu.com/p/386a79d16e05</a></p>
</blockquote>
<p>导入 MySQL 驱动包：</p>
<blockquote>
<p>Java MySQL 连接:<a href="https://eslsuwen.github.io/2019/06/02/Java-MySQL/" target="_blank" rel="noopener">https://eslsuwen.github.io/2019/06/02/Java-MySQL/</a></p>
</blockquote>
<h1 id="1-创建测试数据"><a href="#1-创建测试数据" class="headerlink" title="1.创建测试数据"></a>1.创建测试数据</h1><p>接下来我们在 MySQL 中创建 usersdb 数据库，并创建 user 数据表，表结构如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">CREATE TABLE `user` (</span><br><span class="line">  `name` char(20) NOT NULL DEFAULT &apos;&apos; COMMENT &apos;name&apos;,</span><br><span class="line">  `password` char(10) NOT NULL DEFAULT &apos;&apos; COMMENT &apos;password&apos;</span><br><span class="line">) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;</span><br></pre></td></tr></table></figure></p>
<p>插入一些数据：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">INSERT INTO `user`</span><br><span class="line">VALUES</span><br><span class="line">	( &apos;admin&apos;, &apos;admin&apos; ),</span><br><span class="line">	( &apos; guest &apos;, &apos; 123456 &apos; ),</span><br><span class="line">	( &apos; guest1 &apos;, &apos; 123 &apos; );</span><br></pre></td></tr></table></figure></p>
<p><img src="/2019/06/03/Java-Login/1.png" alt="1"></p>
<h1 id="2-创建登录-jsp-文件"><a href="#2-创建登录-jsp-文件" class="headerlink" title="2.创建登录 jsp 文件"></a>2.创建登录 jsp 文件</h1><p>在 web 目录下创建 login.jsp :<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=UTF-8&quot;</span><br><span class="line">         pageEncoding=&quot;UTF-8&quot; %&gt;</span><br><span class="line">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;</span><br><span class="line">    &lt;title&gt;登录&lt;/title&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">&lt;div class=&quot;login&quot; style=&quot;text-align:center;&quot;&gt;</span><br><span class="line">    &lt;fieldset&gt;</span><br><span class="line">        &lt;legend&gt;用户登录&lt;/legend&gt;</span><br><span class="line">        &lt;br/&gt;</span><br><span class="line">        &lt;form action=&quot;login&quot; method=&quot;post&quot; name=&quot;login&quot;&gt;</span><br><span class="line">            用户名：&lt;input type=&quot;text&quot; name=&quot;username&quot;/&gt; &lt;br/&gt; &lt;br/&gt; 密&amp;nbsp;码：&lt;input</span><br><span class="line">                type=&quot;password&quot; name=&quot;password&quot;/&gt; &lt;br/&gt; &lt;br/&gt; &lt;input</span><br><span class="line">                type=&quot;submit&quot; value=&quot;登录&quot;/&gt;</span><br><span class="line">        &lt;/form&gt;</span><br><span class="line">    &lt;/fieldset&gt;</span><br><span class="line">&lt;/div&gt;</span><br><span class="line"></span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure></p>
<h1 id="3-创建登录-servlet-处理登录请求"><a href="#3-创建登录-servlet-处理登录请求" class="headerlink" title="3.创建登录 servlet 处理登录请求"></a>3.创建登录 servlet 处理登录请求</h1><ul>
<li>登录成功跳转预设 jsp 文件</li>
<li>所使用 JDBC 操作类参考下文<blockquote>
<p>Java MySQL 连接:<a href="https://eslsuwen.github.io/2019/06/02/Java-MySQL/" target="_blank" rel="noopener">https://eslsuwen.github.io/2019/06/02/Java-MySQL/</a></p>
</blockquote>
</li>
<li>登录失败则跳回 login.jsp</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br></pre></td><td class="code"><pre><span class="line">package login;</span><br><span class="line"></span><br><span class="line">import database.JdbcOp;</span><br><span class="line"></span><br><span class="line">import javax.servlet.ServletException;</span><br><span class="line">import javax.servlet.annotation.WebServlet;</span><br><span class="line">import javax.servlet.http.HttpServlet;</span><br><span class="line">import javax.servlet.http.HttpServletRequest;</span><br><span class="line">import javax.servlet.http.HttpServletResponse;</span><br><span class="line">import javax.servlet.http.HttpSession;</span><br><span class="line">import java.io.IOException;</span><br><span class="line">import java.io.PrintWriter;</span><br><span class="line">import java.sql.ResultSet;</span><br><span class="line"></span><br><span class="line">@WebServlet(&quot;/login&quot;)</span><br><span class="line">public class LoginServlet extends HttpServlet &#123;</span><br><span class="line">    private static final long serialVersionUID = 1L;</span><br><span class="line"></span><br><span class="line">    protected void doGet(HttpServletRequest request, HttpServletResponse response)</span><br><span class="line">            throws ServletException, IOException &#123;</span><br><span class="line">        // 一般都会在doGet()方法中调用doPost()方法，或者在doPost()方法中调用doGet()方法</span><br><span class="line">        doPost(request, response);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    protected void doPost(HttpServletRequest request, HttpServletResponse response)</span><br><span class="line">            throws ServletException, IOException &#123;</span><br><span class="line">        // 设置编码格式，可以防止乱码出现</span><br><span class="line">        response.setContentType(&quot;text/html; charset=utf-8&quot;);</span><br><span class="line">        response.setCharacterEncoding(&quot;utf-8&quot;);</span><br><span class="line">        request.setCharacterEncoding(&quot;utf-8&quot;);</span><br><span class="line">        // 获取用户提交过来的用户名和密码，是通过表单中input的name属性获取的</span><br><span class="line">        String username = request.getParameter(&quot;username&quot;);</span><br><span class="line">        String password = request.getParameter(&quot;password&quot;);</span><br><span class="line">        String isSignUp = request.getParameter(&quot;isSignUp&quot;);</span><br><span class="line">        PrintWriter out = response.getWriter();</span><br><span class="line">        System.out.println(username + &quot;: &quot; + password + &quot; isSignUp: &quot; + isSignUp);</span><br><span class="line">        // 获取输出流，用户显示信息，也可以用转发或者重定向</span><br><span class="line">        PrintWriter pw = response.getWriter();</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        try &#123;</span><br><span class="line">            JdbcOp jdbc = new JdbcOp();</span><br><span class="line">            jdbc.open(&quot;usersdb&quot;);</span><br><span class="line">            ResultSet rs = jdbc.executeQuery(&quot;select * from users&quot;);</span><br><span class="line"></span><br><span class="line">            while (rs.next()) &#123;</span><br><span class="line">                String nm = rs.getString(&quot;name&quot;);</span><br><span class="line">                String pd = rs.getString(&quot;password&quot;);</span><br><span class="line">                System.out.println(&quot;username: &quot; + nm + &quot; password: &quot; + pd);</span><br><span class="line"></span><br><span class="line">                if (nm.equals(username) &amp;&amp; pd.equals(password)) &#123;</span><br><span class="line">                    HttpSession session = request.getSession();</span><br><span class="line">                    //将数据存储到session中</span><br><span class="line">                    session.setAttribute(&quot;isLogin&quot;, &quot;true&quot;);</span><br><span class="line">                    session.setAttribute(&quot;username&quot;, username);</span><br><span class="line"></span><br><span class="line">                    out.print(&quot;&lt;script language=&apos;javascript&apos;&gt;alert(&apos;You login successful  ! 你已成功登录！out.print&apos;);window.location.href=&apos;test.jsp&apos;;&lt;/script&gt;&quot;);</span><br><span class="line">                    out.flush();</span><br><span class="line">                    out.close();</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            jdbc.close();</span><br><span class="line">        &#125; catch (Exception e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">        pw.write(&quot;login fail&quot;);</span><br><span class="line">        out.print(&quot;&lt;script language=&apos;javascript&apos;&gt;alert(&apos;please login first 登陆信息输入有误！&apos;);window.location.href=&apos;login.jsp&apos;;&lt;/script&gt;&quot;);</span><br><span class="line">        out.flush();</span><br><span class="line">        out.close();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="4-运行项目"><a href="#4-运行项目" class="headerlink" title="4.运行项目"></a>4.运行项目</h1><p><img src="/2019/06/03/Java-Login/2.png" alt="2"></p>
<p>输入正确的账号密码：</p>
<p><img src="/2019/06/03/Java-Login/3.png" alt="3"></p>
<p>账号密码验证失败：</p>
<p><img src="/2019/06/03/Java-Login/4.png" alt="4"></p>

      
    </div><!-- .entry-content -->

    <footer class="entry-meta">
    <a href="/2019/06/03/Java-Login/">
    <time datetime="2019-06-03T01:26:14.000Z" class="entry-date">
        2019-06-03
    </time>
</a>
    
  <span class="article-delim">&#8226;</span>
  <div class="article-category">
  <a class="article-category-link" href="/categories/JAVA企业开发框架/">JAVA企业开发框架</a>
  </div>

    
  <span class="article-delim">&#8226;</span>
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/java/">java</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/mysql/">mysql</a></li></ul>

    </footer>
</article>






  
    <article id="post-Java-MySQL" class="post-Java-MySQL post type-post status-publish format-standard hentry">
    <!---->

      <header class="entry-header">
        
        
  
    <h1 class="entry-title">
      <a class="article-title" href="/2019/06/02/Java-MySQL/">Java MySQL 连接</a>
    </h1>
  

        
        <div class="comments-link">
            
            <a href="javascript:void(0);" data-url="http://yoursite.com/2019/06/02/Java-MySQL/" data-id="ck2tq8ure0006sj77e6n5to39" class="leave-reply bdsharebuttonbox" data-cmd="more">Share</a>
        </div><!-- .comments-link -->
      </header><!-- .entry-header -->

    <div class="entry-content">
      
        <h1 id="0-环境准备"><a href="#0-环境准备" class="headerlink" title="0.环境准备"></a>0.环境准备</h1><p>Java 连接 MySQL 需要驱动包，最新版下载地址为：<a href="http://dev.mysql.com/downloads/connector/j/" target="_blank" rel="noopener">http://dev.mysql.com/downloads/connector/j/</a>, 解压后得到 jar 库文件，然后在对应的项目中导入该库文件。<br>本实例使用的是 IDEA，导入 jar 包：<br><img src="/2019/06/02/Java-MySQL/1.png" alt="1"><br>也可直接放到 jdk 里，路径为：</p>
<blockquote>
<p>*\Java\jdk1.8.0_121\jre\lib\</p>
</blockquote>
<h1 id="1-创建测试数据"><a href="#1-创建测试数据" class="headerlink" title="1.创建测试数据"></a>1.创建测试数据</h1><p>接下来我们在 MySQL 中创建 Test 数据库，并创建 websites 数据表，表结构如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">CREATE TABLE `websites` (</span><br><span class="line">  `id` int(11) NOT NULL AUTO_INCREMENT,</span><br><span class="line">  `name` char(20) NOT NULL DEFAULT &apos;&apos; COMMENT &apos; 站点名称&apos;,</span><br><span class="line">  `url` varchar(255) NOT NULL DEFAULT &apos;&apos;,</span><br><span class="line">  `alexa` int(11) NOT NULL DEFAULT &apos;0&apos; COMMENT &apos;Alexa 排名&apos;,</span><br><span class="line">  `country` char(10) NOT NULL DEFAULT &apos;&apos; COMMENT &apos; 国家&apos;,</span><br><span class="line">  PRIMARY KEY (`id`)</span><br><span class="line">) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;</span><br></pre></td></tr></table></figure></p>
<p>插入一些数据：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">INSERT INTO `websites`</span><br><span class="line">VALUES</span><br><span class="line">	( &apos;1&apos;, &apos;Google&apos;, &apos;https://www.google.cm/&apos;, &apos;1&apos;, &apos;USA&apos; ),</span><br><span class="line">	( &apos;2&apos;, &apos; 淘宝&apos;, &apos;https://www.taobao.com/&apos;, &apos;13&apos;, &apos;CN&apos; ),</span><br><span class="line">	( &apos;3&apos;, &apos; 腾讯&apos;, &apos;http://www.qq.com&apos;, &apos;5892&apos;, &apos;&apos; ),</span><br><span class="line">	( &apos;4&apos;, &apos; 微博&apos;, &apos;http://weibo.com/&apos;, &apos;20&apos;, &apos;CN&apos; ),</span><br><span class="line">	( &apos;5&apos;, &apos;Facebook&apos;, &apos;https://www.facebook.com/&apos;, &apos;3&apos;, &apos;USA&apos; );</span><br></pre></td></tr></table></figure></p>
<p>数据表显示如下：<br><img src="/2019/06/02/Java-MySQL/2.png" alt="2"></p>
<h1 id="2-连接数据库"><a href="#2-连接数据库" class="headerlink" title="2.连接数据库"></a>2.连接数据库</h1><p>以下实例使用了 JDBC 连接 MySQL 数据库，注意一些数据如用户名，密码需要根据你的开发环境来配置：</p>
<p>创建 JDBC 操作类：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line">package database;</span><br><span class="line"></span><br><span class="line">import java.sql.*;</span><br><span class="line"></span><br><span class="line">public class JdbcOp &#123;</span><br><span class="line"></span><br><span class="line">    private Connection conn = null;</span><br><span class="line">    private Statement statement = null;</span><br><span class="line">    // JDBC 驱动名及数据库 URL</span><br><span class="line">    private final String driver=&quot;com.mysql.cj.jdbc.Driver&quot;;</span><br><span class="line">    private final String jdbcUrl=&quot;jdbc:mysql://localhost:3306/&quot;;</span><br><span class="line">    private final String UrlParam = &quot;?useUnicode=true&amp;characterEncoding=UTF-8&amp;useJDBCCompliantTimezoneShift=true&amp;useLegacyDatetimeCode=false&amp;serverTimezone=UTC&quot;;</span><br><span class="line">    // 数据库的用户名与密码，需要根据自己的设置</span><br><span class="line">    private final String userName=&quot;youraccount&quot;;</span><br><span class="line">    private final String userPwd=&quot;yourpassword&quot;;</span><br><span class="line">    public void open(String Url) &#123;</span><br><span class="line">        try &#123;</span><br><span class="line">            Class.forName(driver).newInstance();</span><br><span class="line">            conn = DriverManager.getConnection(jdbcUrl+Url+UrlParam, userName, userPwd);</span><br><span class="line">            statement = conn.createStatement();</span><br><span class="line">        &#125; catch (Exception e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public int executeUpdate(String sql) &#123;</span><br><span class="line">        try &#123;</span><br><span class="line">            return statement.executeUpdate(sql);</span><br><span class="line">        &#125; catch (SQLException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">            return -1;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public ResultSet executeQuery(String sql) &#123;</span><br><span class="line">        try &#123;</span><br><span class="line">            return statement.executeQuery(sql);</span><br><span class="line">        &#125; catch (SQLException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">            return null;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void close() &#123;</span><br><span class="line">        try &#123;</span><br><span class="line">            conn.close();</span><br><span class="line">            statement.close();</span><br><span class="line">        &#125; catch (SQLException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>创建 JDBC 测试类：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">package database;</span><br><span class="line"></span><br><span class="line">import java.sql.ResultSet;</span><br><span class="line"></span><br><span class="line">public class JdbcTest &#123;</span><br><span class="line">    public static void main(String[] args) &#123;</span><br><span class="line">        try &#123;</span><br><span class="line">            JdbcOp jdbc = new JdbcOp();</span><br><span class="line">            jdbc.open(&quot;Test&quot;);</span><br><span class="line">            // 执行查询</span><br><span class="line">            ResultSet rs = jdbc.executeQuery(&quot;SELECT id, name, url FROM websites&quot;);</span><br><span class="line">            // 展开结果集数据库</span><br><span class="line">            while (rs.next()) &#123;</span><br><span class="line">                // 通过字段检索</span><br><span class="line">                int id  = rs.getInt(&quot;id&quot;);</span><br><span class="line">                String name = rs.getString(&quot;name&quot;);</span><br><span class="line">                String url = rs.getString(&quot;url&quot;);</span><br><span class="line">                // 输出数据</span><br><span class="line">                 System.out.print(&quot;ID: &quot; + id);</span><br><span class="line">                System.out.print(&quot;, 站点名称: &quot; + name);</span><br><span class="line">                System.out.print(&quot;, 站点 URL: &quot; + url);</span><br><span class="line">                System.out.print(&quot;\n&quot;);</span><br><span class="line">            &#125;</span><br><span class="line">            // 完成后关闭</span><br><span class="line">            jdbc.close();</span><br><span class="line">        &#125; catch (Exception e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>以上实例执行输出结果如下：<br><img src="/2019/06/02/Java-MySQL/3.png" alt="3"></p>

      
    </div><!-- .entry-content -->

    <footer class="entry-meta">
    <a href="/2019/06/02/Java-MySQL/">
    <time datetime="2019-06-02T14:04:45.000Z" class="entry-date">
        2019-06-02
    </time>
</a>
    
  <span class="article-delim">&#8226;</span>
  <div class="article-category">
  <a class="article-category-link" href="/categories/JAVA企业开发框架/">JAVA企业开发框架</a>
  </div>

    
  <span class="article-delim">&#8226;</span>
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/java/">java</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/mysql/">mysql</a></li></ul>

    </footer>
</article>






  
    <article id="post-sakila-database" class="post-sakila-database post type-post status-publish format-standard hentry">
    <!---->

      <header class="entry-header">
        
        
  
    <h1 class="entry-title">
      <a class="article-title" href="/2019/06/02/sakila-database/">Sakila MySQL 样例数据库解析</a>
    </h1>
  

        
        <div class="comments-link">
            
            <a href="javascript:void(0);" data-url="http://yoursite.com/2019/06/02/sakila-database/" data-id="ck2tq8usx000vsj77luxjn0qr" class="leave-reply bdsharebuttonbox" data-cmd="more">Share</a>
        </div><!-- .comments-link -->
      </header><!-- .entry-header -->

    <div class="entry-content">
      
        <h1 id="0-前言"><a href="#0-前言" class="headerlink" title="0.前言"></a>0.前言</h1><p>Sakila 可以作为数据库设计的参考，也可作为实验数据。本例是用作数据分析学习的实验数据。</p>
<blockquote>
<p>The Sakila sample database was developed by Mike Hillyer, a former member of the MySQL AB documentation team, and is intended to provide a standard schema that can be used for examples in books, tutorials, articles, samples, and so forth. Sakila sample database also serves to highlight the latest features of MySQL such as Views, Stored Procedures, and Triggers.</p>
</blockquote>
<h1 id="1-实验环境"><a href="#1-实验环境" class="headerlink" title="1.实验环境"></a>1.实验环境</h1><h3 id="方法一：安装-MySQL-时选择-FULL-完全安装"><a href="#方法一：安装-MySQL-时选择-FULL-完全安装" class="headerlink" title="方法一：安装 MySQL 时选择 FULL 完全安装"></a>方法一：安装 MySQL 时选择 FULL 完全安装</h3><p>安装 MySQL 时选择 FULL 完全安装，默认安装了 Sakila sample database<br><img src="/2019/06/02/sakila-database/1.png" alt="1"></p>
<h3 id="方法二：下载后导入"><a href="#方法二：下载后导入" class="headerlink" title="方法二：下载后导入"></a>方法二：下载后导入</h3><p>下载地址：</p>
<ul>
<li><a href="http://downloads.mysql.com/docs/sakila-db.zip" target="_blank" rel="noopener">ZIP 格式</a></li>
<li><a href="http://downloads.mysql.com/docs/sakila-db.tar.gz" target="_blank" rel="noopener">tar 格式</a></li>
<li><a href="http://dev.mysql.com/doc/sakila/en/index.html" target="_blank" rel="noopener">官方文档</a></li>
</ul>
<p>解压后得到三个文件：</p>
<ol>
<li>sakila-schema.sql 文件包含创建 Sakila 数据库的结构：表、视图、存储过程和触发器</li>
<li>sakila-data.sql 文件包含：使用 INSERT 语句填充数据及在初始数据加载后，必须创建的触发器的定义</li>
<li>sakila.mwb 文件是一个 MySQL Workbench 数据模型，可以在 MySQL 的工作台打开查看数据库结构。</li>
</ol>
<blockquote>
<p>导入参考： <a href="http://dev.mysql.com/doc/sakila/en/sakila-installation.html" target="_blank" rel="noopener">http://dev.mysql.com/doc/sakila/en/sakila-installation.html</a></p>
</blockquote>
<pre><code>shell&gt; mysql -u root -p
mysql&gt; SOURCE C:/temp/sakila-db/sakila-schema.sql;
mysql&gt; SOURCE C:/temp/sakila-db/sakila-data.sql;
</code></pre><h1 id="2-数据结构"><a href="#2-数据结构" class="headerlink" title="2.数据结构"></a>2.数据结构</h1><p>Sakila 样例数据库包括 16 张表格，7 个视图，3 个 Stored Procedures，3 个 Functions，6 个 Triggers。英文描述点开相应连接即可查看。<br>总览：<br><img src="/2019/06/02/sakila-database/2.png" alt="2"><br>关系图:<br><img src="/2019/06/02/sakila-database/3.png" alt="3"></p>
<h1 id="3-视图"><a href="#3-视图" class="headerlink" title="3.视图"></a>3.视图</h1><p>actor_info 视图提供了所有演员的列表及所演的电影，电影按 category 分组.<br>actor → film_actor → film →  film_category → category</p>
<ol>
<li>actor_id: 代理主键用于唯一标识表中的每个演员</li>
<li>first_name: 演员的名字</li>
<li>last_name: 演员的姓氏</li>
<li>last_update: 该行已创建或最近更新的时间</li>
</ol>
<p><img src="/2019/06/02/sakila-database/4.png" alt="4"></p>
<p>客户列表，firstname和lastname连接成fullname，将 address, city, country 集成在一个视图里<br>customer → address → city → country</p>
<ol>
<li>stomer_id: 代理主键用于唯一标识表中的每个客户</li>
<li>store_id: 一个外键，确定客户所属的 store。</li>
<li>first_name: 客户的名字</li>
<li>last_name: 客户的姓氏</li>
<li>email: 客户的电子邮件地址</li>
<li>address_id: 使用在地址 表的外键来确定客户的地址</li>
<li>active: 表示客户是否是活跃的客户</li>
<li>create_date: 顾客被添加到系统中的日期。使用 INSERT 触发器自动设置。</li>
<li>last_update: 该行已创建或最近更新的时间</li>
</ol>
<p><img src="/2019/06/02/sakila-database/5.png" alt="5"></p>
<p>每个电影种类的销售额<br>payment → rental → inventory → film → film_category → category</p>
<p><img src="/2019/06/02/sakila-database/6.png" alt="6"></p>
<p>每个商店的 manager 及销售额。<br>payment → rental → inventory → store → staff</p>
<p>store 表列出了系统中的所有商店 。<br>store 使用外键来标识工作人员和地址；在员工、客户、库存表被作为外键使用。</p>
<ol>
<li>store_id: 代理主键唯一标识的商店</li>
<li>manager_staff_id: 使用外键来标识这家商店的经理</li>
<li>address_id: 使用外键来确定这家店的地址</li>
<li>last_update: 该行已创建或最近更新的时间</li>
</ol>
<p><img src="/2019/06/02/sakila-database/7.png" alt="7"></p>
<p>工作人员的列表</p>
<p>工作人员表列出了所有的工作人员，包括电子邮件地址，登录信息和图片信息 。<br>工作人员表是指使用外键来标识存储和地址表；在出租、支付和商店表中作为外键。</p>
<ol>
<li>staff_id: 代理主键唯一标识的工作人员</li>
<li>first_name: 工作人员的名字</li>
<li>last_name: 工作人员的姓氏</li>
<li>address_id: 工作人员的地址在地址表的外键</li>
<li>picture: 工作人员的照片，使用了 BLOB 属性</li>
<li>email: 工作人员的电子邮件地址</li>
<li>store_id: 工作人员所在的商店，用外键标识</li>
<li>active: 是否是活跃的工作人员。</li>
<li>username: 用户名，由工作人员用来访问租赁系统</li>
<li>password: 工作人员访问租赁系统所使用的密码。使用了 SHA1 函数</li>
<li>last_update: 该行已创建或最近更新的时间</li>
<li>active: 是否有效，删除时设置为 False</li>
</ol>
<p><img src="/2019/06/02/sakila-database/8.png" alt="8"></p>
<h1 id="4-数据分析"><a href="#4-数据分析" class="headerlink" title="4.数据分析"></a>4.数据分析</h1><p><em>最具有购买潜力的顾客</em>：</p>
<p>从600位顾客中去发现和找出最具有购买潜力的顾客，找出他们的邮箱地址和联系方法，并给他们发送邮件进行感谢，以保持该部分用户的持续购买欲望，增加用户的满意度，以此来保持商品的销售量。</p>
<h3 id="0-数据获取"><a href="#0-数据获取" class="headerlink" title="0.数据获取"></a>0.数据获取</h3><p>根据customer、payment两个表进行数据筛选，获得顾客编号：customer.customer_id 顾客编号；计算总消费金额;最后根据顾客消费总金额降序排列。<br><img src="/2019/06/02/sakila-database/9.png" alt="9"><br>具体代码：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">SELECT</span><br><span class="line">  customer1.customer_id 顾客编号,</span><br><span class="line">	CONCAT( customer1.`first_name`, CONCAT( &quot; &quot;, customer1.`last_name` ) ) AS &apos;顾客名&apos;,</span><br><span class="line">	FORMAT(sum(payment.amount),2) AS &apos;消费金额&apos;</span><br><span class="line">FROM</span><br><span class="line">	customer1,</span><br><span class="line">	payment</span><br><span class="line">WHERE</span><br><span class="line">	customer1.customer_id = payment.customer_id</span><br><span class="line">GROUP BY</span><br><span class="line">	CONCAT( customer1.`first_name`, CONCAT( &quot; &quot;, customer1.`last_name` ) )</span><br><span class="line">ORDER BY</span><br><span class="line">	FORMAT(sum(payment.amount),2)+0 DESC</span><br></pre></td></tr></table></figure></p>
<h3 id="1-连接顾客姓名"><a href="#1-连接顾客姓名" class="headerlink" title="1.连接顾客姓名"></a>1.连接顾客姓名</h3><p>通过筛选address_id连接customer和address两表得到顾客的编号、地址、电话，然后通过顾客的编号升序排列。<br><img src="/2019/06/02/sakila-database/10.png" alt="10"><br>具体代码：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">SELECT</span><br><span class="line">CONCAT( customer1.`first_name`, CONCAT( &quot; &quot;, customer1.`last_name` ) ) AS 顾客姓名,</span><br><span class="line">customer1.customer_id 顾客编号,</span><br><span class="line">address.address 顾客地址,</span><br><span class="line">address.phone 顾客电话,</span><br><span class="line">customer1.email</span><br><span class="line">FROM</span><br><span class="line">customer1 ,</span><br><span class="line">address</span><br><span class="line">WHERE</span><br><span class="line">	customer1.address_id=address.address_id</span><br><span class="line">GROUP BY</span><br><span class="line">	CONCAT( customer1.`first_name`, CONCAT( &quot; &quot;, customer1.`last_name` ) )</span><br><span class="line">ORDER BY</span><br><span class="line">  customer1.customer_id+0 ASC</span><br></pre></td></tr></table></figure></p>
<h3 id="2-结果分析"><a href="#2-结果分析" class="headerlink" title="2.结果分析"></a>2.结果分析</h3><p>通过表一得到散点图：</p>
<p><img src="/2019/06/02/sakila-database/11.png" alt="11"></p>
<p>根据数据分析我们可以看到顾客KARL SEAL的消费金额221.55是600位顾客中消费总金额最高的一位，他便是最有潜力的顾客，然后我们可以通过表二去得到他的联系信息。<br>通过散点图我们可以分析到大多数的顾客消费总金额分布在120元上下，所以我们以120元为界，将消费总金额在120元以上顾客列为有购买潜力的顾客，从表二寻找他们的联系方式，批量对他们发送邮件进行感谢。</p>

      
    </div><!-- .entry-content -->

    <footer class="entry-meta">
    <a href="/2019/06/02/sakila-database/">
    <time datetime="2019-06-02T08:22:59.000Z" class="entry-date">
        2019-06-02
    </time>
</a>
    
  <span class="article-delim">&#8226;</span>
  <div class="article-category">
  <a class="article-category-link" href="/categories/DATABASE/">DATABASE</a>
  </div>

    
  <span class="article-delim">&#8226;</span>
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/mysql/">mysql</a></li></ul>

    </footer>
</article>






  
    <article id="post-servlet转发" class="post-servlet转发 post type-post status-publish format-standard hentry">
    <!---->

      <header class="entry-header">
        
        
  
    <h1 class="entry-title">
      <a class="article-title" href="/2019/05/24/servlet转发/">Servlet 的三种跳转方式</a>
    </h1>
  

        
        <div class="comments-link">
            
            <a href="javascript:void(0);" data-url="http://yoursite.com/2019/05/24/servlet转发/" data-id="ck2tq8usz000zsj77e1m3be1d" class="leave-reply bdsharebuttonbox" data-cmd="more">Share</a>
        </div><!-- .comments-link -->
      </header><!-- .entry-header -->

    <div class="entry-content">
      
        <h2 id="1-Forword"><a href="#1-Forword" class="headerlink" title="1.Forword"></a>1.Forword</h2><hr>
<p>request.getRequestDispatcher (“url”).forword (request,response) 是请求转发，也就是说，一个 Servlet 向当前的</p>
<p>Servlet 发出请求后，经过这个方法后，请求会继续转发到请求的 URL, 在这个过程中，只向服务器发出一次请求。效率当然也就高了.<br>从在浏览器地址栏中显示的 URL 来看，response.sendRedirect (“url”), 地址栏中的 URL 会发生变化，会显示重定向的这个 URL 的地址，<br>而 request.getRequestDispatcher (“url”).forword (request,response) 这种方法，地址栏中的地址是不变的.<br>示例如下：<br>先创建 servlet 实例：a.java 代码如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line">package package1;</span><br><span class="line"></span><br><span class="line">import java.io.IOException;</span><br><span class="line">import javax.servlet.ServletException;</span><br><span class="line">import javax.servlet.annotation.WebServlet;</span><br><span class="line">import javax.servlet.http.HttpServlet;</span><br><span class="line">import javax.servlet.http.HttpServletRequest;</span><br><span class="line">import javax.servlet.http.HttpServletResponse;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * Servlet implementation class a</span><br><span class="line"> */</span><br><span class="line">@WebServlet(&quot;/a&quot;)</span><br><span class="line">public class a extends HttpServlet &#123;</span><br><span class="line">	private static final long serialVersionUID = 1L;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * @see HttpServlet#HttpServlet()</span><br><span class="line">     */</span><br><span class="line">    public a() &#123;</span><br><span class="line">        super();</span><br><span class="line">        // TODO Auto-generated constructor stub</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)</span><br><span class="line">	 */</span><br><span class="line">	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		//第一种 请求转发</span><br><span class="line">		request.setAttribute(&quot;message&quot;,&quot;aaaaaa&quot;);</span><br><span class="line">		request.getRequestDispatcher(&quot;/b&quot;).forward(request,response);</span><br><span class="line">		// 第二种 重定向</span><br><span class="line">		response.setContentType(&quot;text/html; charset=UTF-8&quot;);</span><br><span class="line">		response.sendRedirect(&quot;/Tomcat_Test/b&quot;);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)</span><br><span class="line">	 */</span><br><span class="line">	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line"></span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>创建 servlet 实例：b.java 代码如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line">package package1;</span><br><span class="line"></span><br><span class="line">import java.io.IOException;</span><br><span class="line">import javax.servlet.ServletException;</span><br><span class="line">import javax.servlet.annotation.WebServlet;</span><br><span class="line">import javax.servlet.http.HttpServlet;</span><br><span class="line">import javax.servlet.http.HttpServletRequest;</span><br><span class="line">import javax.servlet.http.HttpServletResponse;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * Servlet implementation class b</span><br><span class="line"> */</span><br><span class="line">@WebServlet(&quot;/b&quot;)</span><br><span class="line">public class b extends HttpServlet &#123;</span><br><span class="line">	private static final long serialVersionUID = 1L;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * @see HttpServlet#HttpServlet()</span><br><span class="line">     */</span><br><span class="line">    public b() &#123;</span><br><span class="line">        super();</span><br><span class="line">        // TODO Auto-generated constructor stub</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)</span><br><span class="line">	 */</span><br><span class="line">	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		response.setCharacterEncoding(&quot;utf-8&quot;);</span><br><span class="line">		String message=(String)request.getAttribute(&quot;message&quot;);</span><br><span class="line">		response.getWriter().append(&quot;this is B page with message from A: &quot;).append(message);</span><br><span class="line"></span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)</span><br><span class="line">	 */</span><br><span class="line">	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException &#123;</span><br><span class="line">		// TODO Auto-generated method stub</span><br><span class="line">		doGet(request, response);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>先注释<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">// 第二种 重定向</span><br><span class="line">response.setContentType(&quot;text/html; charset=UTF-8&quot;);</span><br><span class="line">response.sendRedirect(&quot;/Tomcat_Test/b&quot;);</span><br></pre></td></tr></table></figure></p>
<p>运行 a.java 测试“请求转发”</p>
<p><img src="/2019/05/24/servlet转发/1.png" alt="1"></p>
<p><em>getRequestDispatcher () 方法的参数必须以 “/” 开始，“/” 表示本 Web 应用程序的根目录。如上例中，表示要跳转的地址为 <a href="http://localhost:8080/servlet/b" target="_blank" rel="noopener">http://localhost:8080/servlet/b</a></em></p>
<p>forward 是最常用的方式，在 Structs 等 MVC 框架中，都是用 Servlet 来处理用户请求，把结果通过 request.setAttribute () 放到 request 中，<br>然后 forward 到 JSP 中显示。<br>当执行 forward 方法时，不能有任何输出到达客户端，否则会抛出异常，也就是说，在 forward 之前，不要使用 out.println () 语句向客户端输出。</p>
<p>尤其注意 HttpServlet 默认的 super.doGet () 和 super.goPost () 方法都包含了相关操作，所以在使用时应该把这两个方法注释掉！！</p>
<h2 id="2-Redirect"><a href="#2-Redirect" class="headerlink" title="2.Redirect"></a>2.Redirect</h2><hr>
<p>这种方式要传值出去的话，只能在 url 中带 parameter 或者放在 session 中，无法使用 request.setAttribute 来传递。<br>这种方式是在客户端作的重定向处理。该方法通过修改 HTTP 协议的 HEADER 部分，对浏览器下达重定向指令的，让浏览器对在 location 中指定的 URL 提出请求，使浏览器显示重定向网页的内容。该方法可以接受绝对的或相对的 URLs。如果传递到该方法的参数是一个相对的 URL，那么 Web container 在将它发送到客户端前会把它转换成一个绝对的 URL。</p>
<p>注释<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">// 第一种 请求转发</span><br><span class="line">response.setContentType(&quot;text/html; charset=UTF-8&quot;);</span><br><span class="line">response.sendRedirect(&quot;/Tomcat_Test/b&quot;);</span><br></pre></td></tr></table></figure></p>
<p>运行 a.java 测试“重定向”</p>
<p><img src="/2019/05/24/servlet转发/2.png" alt="2"></p>
<h2 id="3-JavaScript"><a href="#3-JavaScript" class="headerlink" title="3.JavaScript"></a>3.JavaScript</h2><hr>
<p>另还有一种跳转页面的方法，也就是在 Servlet 中输出 JavaScript 代码，也能实现页面的跳转</p>
<pre><code>PrintWriter out = request.getWriter();
out.println(&quot;&lt;script&gt;window.location.href = &quot;url&quot;&lt;/script&gt;&quot;);
out.flush();
out.close();
</code></pre><p>这种方法和 response.sendRedirect () 的效率是差不多的，也要向服务器发出再次请求才能跳转到的 URL。</p>
<h2 id="4-小结"><a href="#4-小结" class="headerlink" title="4.小结"></a>4.小结</h2><hr>
<ul>
<li>0、跳转 (forward) 是在服务器端实现的，客户端浏览器并不知道该浏览动作，而使用 sendRedirect 跳转时，跳转是在客户端实现的，也就是说客户端浏览器实际上请求了 2 次服务器。</li>
<li>1、forward 重定向是在容器内部实现的同一个 Web 应用程序的重定向，所以 forward 方法只能重定向到同一个 Web 应用程序中的一个资源，重定向后浏览器地址栏 URL 不变，而 sendRedirect 方法可以重定向到任何 URL， 因为这种方法是修改 http 头来实现的，URL 没什么限制，重定向后浏览器地址栏 URL 改变。</li>
<li>2、forward 重定向将原始的 HTTP 请求对象（request）从一个 servlet 实例传递到另一个实例，而采用 sendRedirect 方式两者不是同一个 application。</li>
<li>3、基于第二点，参数的传递方式不一样。forward 的 form 参数跟着传递，所以在第二个实例中可以取得 HTTP 请求的参数。sendRedirect 只能通过链接传递参数，response.sendRedirect (“login.jsp?param1=a”)。</li>
<li>4、sendRedirect 能够处理相对 URL，自动把它们转换成绝对 URL，如果地址是相对的，没有一个‘/’，那么 Web container 就认为它是相对于当前的请求 URI 的。比如，如果为 response.sendRedirect (“login.jsp”)，则会从当前 servlet 的 URL 路径下找 login.jsp： <a href="http://10.1.18.8:8081/dms/servlet/Servlet" target="_blank" rel="noopener">http://10.1.18.8:8081/dms/servlet/Servlet</a> 重定向的 URL: <a href="http://10.1.18.8:8081/dms/servlet/login.jsp，如果为" target="_blank" rel="noopener">http://10.1.18.8:8081/dms/servlet/login.jsp，如果为</a> response.sendRedirect (“/login.jsp”) 则会从当前应用径下查找 url:<a href="http://10.1.18.8:8081/login.jsp。而" target="_blank" rel="noopener">http://10.1.18.8:8081/login.jsp。而</a> forward 不能这样处理相对路径。</li>
</ul>

      
    </div><!-- .entry-content -->

    <footer class="entry-meta">
    <a href="/2019/05/24/servlet转发/">
    <time datetime="2019-05-24T00:07:31.000Z" class="entry-date">
        2019-05-24
    </time>
</a>
    
  <span class="article-delim">&#8226;</span>
  <div class="article-category">
  <a class="article-category-link" href="/categories/JAVA企业开发框架/">JAVA企业开发框架</a>
  </div>

    
  <span class="article-delim">&#8226;</span>
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/java/">java</a></li></ul>

    </footer>
</article>






  
    <article id="post-eclipse-servlet" class="post-eclipse-servlet post type-post status-publish format-standard hentry">
    <!---->

      <header class="entry-header">
        
        
  
    <h1 class="entry-title">
      <a class="article-title" href="/2019/05/23/eclipse-servlet/">Eclipse JSP/Servlet 环境搭建</a>
    </h1>
  

        
        <div class="comments-link">
            
            <a href="javascript:void(0);" data-url="http://yoursite.com/2019/05/23/eclipse-servlet/" data-id="ck2tq8urz000bsj77h2j2y4j7" class="leave-reply bdsharebuttonbox" data-cmd="more">Share</a>
        </div><!-- .comments-link -->
      </header><!-- .entry-header -->

    <div class="entry-content">
      
        <h2 id="0-软件下载"><a href="#0-软件下载" class="headerlink" title="0.软件下载"></a>0.软件下载</h2><hr>
<p>本文假定你已安装了 JDK 环境，如未安装，可参阅 Java 开发环境配置 。</p>
<p>我们可以使用 Eclipse 来搭建 JSP 开发环境，首先我们分别下载一下软件包：</p>
<ul>
<li><a href="http://www.eclipse.org/downloads/" target="_blank" rel="noopener">Eclipse J2EE</a></li>
<li><a href="http://tomcat.apache.org/download-70.cgi" target="_blank" rel="noopener">Tomcat</a></li>
</ul>
<h2 id="1-Tomcat-下载安装"><a href="#1-Tomcat-下载安装" class="headerlink" title="1.Tomcat 下载安装"></a>1.Tomcat 下载安装</h2><hr>
<p>你可以根据你的系统下载对应的包 (以下以 Window 系统为例)：<br><img src="/2019/05/23/eclipse-servlet/1.png" alt="1"><br>下载之后，将压缩包解压到 D 盘（你可以自己选择）：<br><img src="/2019/05/23/eclipse-servlet/2.png" alt="2"><br>注意目录名不能有中文和空格。目录介绍如下：</p>
<ul>
<li>bin：二进制执行文件。里面最常用的文件是 startup.bat，如果是 Linux 或 Mac 系统启动文件为 startup.sh。</li>
<li>conf: 配置目录。里面最核心的文件是 server.xml。可以在里面改端口号等。默认端口号是 8080，也就是说，此端口号不能被其他应用程序占用。</li>
<li>lib：库文件。tomcat 运行时需要的 jar 包所在的目录</li>
<li>logs：日志</li>
<li>temp：临时产生的文件，即缓存</li>
<li>webapps：web 的应用程序。web 应用放置到此目录下浏览器可以直接访问</li>
<li>work：编译以后的 class 文件。</li>
</ul>
<p>接着我们可以双击 startup.bat 启动 Tomcat，弹出如下界面：<br><img src="/2019/05/23/eclipse-servlet/3.png" alt="3"><br>这个时候，本地的服务器就已经搭建起来了。如果想关闭服务器，可以直接关闭上面的窗口，或者在里面输入 Ctrl+C 禁止服务。<br>接着我们在浏览器中输入 <a href="http://localhost:8080/" target="_blank" rel="noopener">http://localhost:8080/</a>，如果弹出如下界面，表示 tomcat 安装成功并且启动起来了：<br><img src="/2019/05/23/eclipse-servlet/4.jpg" alt="4"></p>
<h2 id="2-将-Tomcat-和-Eclipse-相关联"><a href="#2-将-Tomcat-和-Eclipse-相关联" class="headerlink" title="2.将 Tomcat 和 Eclipse 相关联"></a>2.将 Tomcat 和 Eclipse 相关联</h2><hr>
<p>选择菜单栏 Windows–&gt;preferences（Mac 系统为 Eclipse–&gt; 偏好设置），弹出如下界面：<br><img src="/2019/05/23/eclipse-servlet/5.png" alt="5"><br>上图中，点击 “add” 的添加按钮，弹出如下界面：<br><img src="/2019/05/23/eclipse-servlet/6.png" alt="6"><br>在选项中，我们选择对应的 Tomcat 版本，接着点击 “Next”，选择 Tomcat 的安装目录，并选择我们安装的 Java 环境：<br><img src="/2019/05/23/eclipse-servlet/7.png" alt="7"><br>点击 “Finish”，完成配置。</p>
<h2 id="3-创建实例"><a href="#3-创建实例" class="headerlink" title="3.创建实例"></a>3.创建实例</h2><hr>
<p>选择 “File–&gt;New–&gt;Dynamic Web Project”，创建 TomcatTest 项目：<br><img src="/2019/05/23/eclipse-servlet/8.png" alt="8"><br><img src="/2019/05/23/eclipse-servlet/9.png" alt="9"><br>点开上图中的红框部分，弹出如下界面：<br><img src="/2019/05/23/eclipse-servlet/10.jpg" alt="10"><br>注意如果已默认选择了我们之前安装的 Tomcat 和 JDK 则可跳过此步。<br>然后，单击 finish, 继续：<br><img src="/2019/05/23/eclipse-servlet/11.png" alt="11"><br><img src="/2019/05/23/eclipse-servlet/12.png" alt="12"><br>工程文件结构：<br><img src="/2019/05/23/eclipse-servlet/13.png" alt="13"><br>上图中各个目录解析：</p>
<ul>
<li>deployment descriptor：部署的描述。</li>
<li>Web App Libraries：自己加的包可以放在里面。</li>
<li>build：放入编译之后的文件。</li>
<li>WebContent: 放进写入的页面。</li>
</ul>
<p>在 WebContent 文件夹下新建一个 hello.jsp 文件。在下图中可以看到它的默认代码：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=UTF-8&quot;</span><br><span class="line">    pageEncoding=&quot;UTF-8&quot;%&gt;</span><br><span class="line">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;</span><br><span class="line">&lt;title&gt;Insert title here&lt;/title&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line"></span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure></p>
<p>接着我们修改下 test.jsp 文件代码如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=UTF-8&quot;</span><br><span class="line">    pageEncoding=&quot;UTF-8&quot; import=&quot;java.util.Date&quot;%&gt;</span><br><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;</span><br><span class="line">&lt;title&gt;hello&lt;/title&gt;</span><br><span class="line">&lt;style&gt;</span><br><span class="line">	body&#123;</span><br><span class="line">		background-color:limegreen;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&lt;/style&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">&lt;h1&gt;今天天气真的好&lt;/h1&gt;</span><br><span class="line">&lt;h2&gt;当前时间 &lt;%=new Date() %&gt;&lt;/h2&gt;</span><br><span class="line"></span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure></p>
<p>接着我们运行该项目:<br><img src="/2019/05/23/eclipse-servlet/14.png" alt="14"><br>会在内置浏览器中输出：<br><img src="/2019/05/23/eclipse-servlet/15.png" alt="15"><br>亦可浏览器访问 <a href="http://localhost:8080/TomcatTest/test.jsp" target="_blank" rel="noopener">http://localhost:8080/TomcatTest/test.jsp</a>, 即可输出正常结果：</p>
<h2 id="4-Servlet实例创建"><a href="#4-Servlet实例创建" class="headerlink" title="4.Servlet实例创建"></a>4.Servlet实例创建</h2><hr>
<p>我们也可以使用以上环境创建 Servlet 文件，选择 “File–&gt;New–&gt;Servlet”:<br><img src="/2019/05/23/eclipse-servlet/16.png" alt="16"><br><img src="/2019/05/23/eclipse-servlet/17.jpg" alt="17"><br>HelloServlet.java 代码如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line">package package1;</span><br><span class="line"></span><br><span class="line">import java.io.IOException;</span><br><span class="line">import javax.servlet.ServletException;</span><br><span class="line">import javax.servlet.annotation.WebServlet;</span><br><span class="line">import javax.servlet.http.HttpServlet;</span><br><span class="line">import javax.servlet.http.HttpServletRequest;</span><br><span class="line">import javax.servlet.http.HttpServletResponse;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * Servlet implementation class HelloServlet</span><br><span class="line"> */</span><br><span class="line">@WebServlet(&quot;/HelloServlet&quot;)</span><br><span class="line">public class HelloServlet extends HttpServlet &#123;</span><br><span class="line">    private static final long serialVersionUID = 1L;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * @see HttpServlet#HttpServlet()</span><br><span class="line">     */</span><br><span class="line">    public HelloServlet() &#123;</span><br><span class="line">        super();</span><br><span class="line">        // TODO Auto-generated constructor stub</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)</span><br><span class="line">     */</span><br><span class="line">    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException &#123;</span><br><span class="line">        // 使用 GBK 设置中文正常显示</span><br><span class="line">        response.setCharacterEncoding(&quot;GBK&quot;);</span><br><span class="line">        response.getWriter().write(&quot;百度：http://www.baidu.com&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)</span><br><span class="line">     */</span><br><span class="line">    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException &#123;</span><br><span class="line">        // TODO Auto-generated method stub</span><br><span class="line">        doGet(request, response);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>创建 /TomcatTest/WebContent/WEB-INF/web.xml 文件（如果没有），代码如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span><br><span class="line">&lt;web-app version=&quot;2.5&quot;</span><br><span class="line">    xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot;</span><br><span class="line">    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span><br><span class="line">    xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee</span><br><span class="line">    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;&gt;</span><br><span class="line">  &lt;servlet&gt;</span><br><span class="line">     &lt;!-- 类名 --&gt;</span><br><span class="line">    &lt;servlet-name&gt;HelloServlet&lt;/servlet-name&gt;</span><br><span class="line">    &lt;!-- 所在的包 --&gt;</span><br><span class="line">    &lt;servlet-class&gt;com.runoob.test.HelloServlet&lt;/servlet-class&gt;</span><br><span class="line">  &lt;/servlet&gt;</span><br><span class="line">  &lt;servlet-mapping&gt;</span><br><span class="line">    &lt;servlet-name&gt;HelloServlet&lt;/servlet-name&gt;</span><br><span class="line">    &lt;!-- 访问的网址 --&gt;</span><br><span class="line">    &lt;url-pattern&gt;/TomcatTest/HelloServlet&lt;/url-pattern&gt;</span><br><span class="line">    &lt;/servlet-mapping&gt;</span><br><span class="line">&lt;/web-app&gt;</span><br></pre></td></tr></table></figure></p>
<blockquote>
<p>Servlet3.0 新特性 (得 Tomcat7.0 版本及以上)，@WebServlet 用于将一个类声明为 Servlet，该注解将会在部署时被容器处理，容器将根据具体的属性配置将相应的类部署为 Servlet。*</p>
</blockquote>
<p>接着重启 Tomcat，浏览器访问 <a href="http://localhost:8080/TomcatTest/HelloServlet：" target="_blank" rel="noopener">http://localhost:8080/TomcatTest/HelloServlet：</a><br><img src="/2019/05/23/eclipse-servlet/18.png" alt="18"></p>

      
    </div><!-- .entry-content -->

    <footer class="entry-meta">
    <a href="/2019/05/23/eclipse-servlet/">
    <time datetime="2019-05-23T12:48:08.000Z" class="entry-date">
        2019-05-23
    </time>
</a>
    
  <span class="article-delim">&#8226;</span>
  <div class="article-category">
  <a class="article-category-link" href="/categories/JAVA企业开发框架/">JAVA企业开发框架</a>
  </div>

    
  <span class="article-delim">&#8226;</span>
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/eclipse/">eclipse</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/jsp/">jsp</a></li></ul>

    </footer>
</article>






  
  
    <nav id="pagination">
      <nav id="page-nav">
        <a class="extend prev" rel="prev" href="/">&laquo; Prev</a><a class="page-number" href="/">1</a><span class="page-number current">2</span><a class="page-number" href="/page/3/">3</a><a class="page-number" href="/page/4/">4</a><a class="extend next" rel="next" href="/page/3/">Next &raquo;</a>
      </nav>
    </nav>
  

</div></div>
        <div id="secondary" class="widget-area" role="complementary">
  
    <aside class="widget">
  <h3 class="widget-title">ABOUT ME</h3>
  <div class="widget-content">
    <p>E-MAIL:esllovesn@gmail.com</p>
    <p>Github: <a href="https://github.com/EslSuwen" target="_blank">EslSuwen</a></p>
    <p>QQ：<a href="tencent://AddContact/?fromId=45&fromSubId=1&subcmd=all&uin=577014284&website=www.oicqzone.com" target="_blank">577014284</a></p>
    <a href="tencent://AddContact/?fromId=45&fromSubId=1&subcmd=all&uin=577014284&website=www.oicqzone.com" target="_blank"><img src="http://q.qlogo.cn/headimg_dl?bs=qq&dst_uin=577014284&src_uin=www.feifeiboke.com&fid=blog&spec=100" alt="hfl"></a>
    <p><strong>#全栈工程师</strong></p>
    <p>“精通 C++/Java/HTML/CSS/JS 等单词的拼写。”</p>
  </div>
</aside>
  
    
<aside class="widget">
  <h3 class="widget-title">Music</h3>
  <div class="widget-content">
    <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width="280" height="86" src="//music.163.com/outchain/player?type=2&id=101092&auto=0&height=66"></iframe>
  </div>
</aside>

  
    
  <aside class="widget">
    <h3 class="widget-title">Recents</h3>
    <div class="widget-content">
      <ul>
        
          <li>
            <a href="/2019/11/11/conceptual-model/">conceptual-model</a>
          </li>
        
          <li>
            <a href="/2019/09/01/ubuntu-install/">Windows 10 &amp; Linux 的艰难历程</a>
          </li>
        
          <li>
            <a href="/2019/06/23/2017gdp-rank/">2017 世界主要国家和地区 GDP 排名</a>
          </li>
        
          <li>
            <a href="/2019/06/09/当前云平台发展现状/">当前云平台发展现状</a>
          </li>
        
          <li>
            <a href="/2019/06/03/Java-Filter/">JavaWeb Filter 实现登录注册过滤</a>
          </li>
        
      </ul>
    </div>
  </aside>

  
    
  <aside class="widget">
    <h3 class="widget-title">Categories</h3>
    <div class="widget-content">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/CODE/">CODE</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/DATABASE/">DATABASE</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/JAVA企业开发框架/">JAVA企业开发框架</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/TEST/">TEST</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/TOOL/">TOOL</a><span class="category-list-count">5</span></li></ul>
    </div>
  </aside>

  
    
  <aside class="widget">
    <h3 class="widget-title">Tags</h3>
    <div class="widget-content">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/c/">c++</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cloud-platforms/">cloud platforms</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/eclipse/">eclipse</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/">git</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/github/">github</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/">java</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/jsp/">jsp</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/markdown/">markdown</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mysql/">mysql</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/tableau/">tableau</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/test/">test</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vscode/">vscode</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/windows/">windows</a><span class="tag-list-count">1</span></li></ul>
    </div>
  </aside>

  
    
  <aside class="widget">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget-content tagcloud">
      <a href="/tags/c/" style="font-size: 10px;">c++</a> <a href="/tags/cloud-platforms/" style="font-size: 10px;">cloud platforms</a> <a href="/tags/eclipse/" style="font-size: 10px;">eclipse</a> <a href="/tags/git/" style="font-size: 13.33px;">git</a> <a href="/tags/github/" style="font-size: 10px;">github</a> <a href="/tags/java/" style="font-size: 20px;">java</a> <a href="/tags/jsp/" style="font-size: 10px;">jsp</a> <a href="/tags/linux/" style="font-size: 10px;">linux</a> <a href="/tags/markdown/" style="font-size: 13.33px;">markdown</a> <a href="/tags/mysql/" style="font-size: 20px;">mysql</a> <a href="/tags/tableau/" style="font-size: 10px;">tableau</a> <a href="/tags/test/" style="font-size: 16.67px;">test</a> <a href="/tags/vscode/" style="font-size: 10px;">vscode</a> <a href="/tags/windows/" style="font-size: 10px;">windows</a>
    </div>
  </aside>

  
    
  <aside class="widget">
    <h3 class="widget-title">Archives</h3>
    <div class="widget-content">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/11/">November 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/09/">September 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/06/">June 2019</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/05/">May 2019</a><span class="archive-list-count">11</span></li></ul>
    </div>
  </aside>

  
    <script>
    // sub title
    var subtitleList = [
        "『卑鄙是卑鄙者的通行证，高尚是高尚者的墓志铭。』——北岛",
        "『所有模型都是错的，但其中一些是有用的。』",
        "『程序员的双手是魔术师的双手，他们把枯燥无味的代码变成了丰富多彩的软件。』——《疯狂的程序员》",
        "『质疑计算机能不能思考，就相当于质疑潜艇能不能游泳。』——Edsger Dijkstra",
        "『人们认为计算机科学是天才的艺术，但是实际情况相反，只是许多人在其它人基础上做一些东西，就像一面由石子垒成的墙。』——高德纳",
        "『Stay young. Stay simple. Always naive!』",
        "『你们媒体千万要记着，不要「见得风，是得雨」。接到消息，你们媒体本身也要判断。』——长者",
        "『假设这些完全无中生有的东西，你再帮他说一遍，你等于......你也有责任吧？』——长者",
        "『刚才你问我啊，我可以回答你一句「无可奉告」。』——长者",
        "『我告诉你们我是身经百战了，见得多了！』——长者",
        "『美国的华莱士，比你们不知要高到哪里去了，我跟他谈笑风生。』——长者",
        "『我有这个必要告诉你们一点，人生的经验。』——长者",
        "『我没有说要钦定，没有任何这个意思。』——长者",
        "『你们啊，不要想喜欢弄个大新闻，说现在已经钦定了，就把我批判一番。』——长者",
        "『一个人的命运啊，当然要靠自我奋斗，但是也要考虑历史的进程。』——长者",
        "『我说另请高明吧，我实在也不是谦虚。』——长者",
        "『苟利国家生死以，岂因祸福避趋之。』——林则徐",
        "『敢同恶鬼争高下，不向霸王让寸分。』——毛泽东",
        "『我生不为逐鹿来，都门懒筑黄金台。状元百官都如狗，总是刀下觳觫材。』——张献忠",
        "『我自成佛自度我，佛度凡尘我度佛。』",
        "『龙吟九天，一曲焚尘；苍山听雪，归时余几人。』",
        "『人最大的痛苦就是说一些自己都不相信的话。』",
        "『燃琴为薪，铸银矢以射白羽；斑音成竹，裁短笛而驭青龙。』",
        "『我们在人生的每个阶段，能影响多少人，就影响多少人，哪怕只能影响一个人，也好过不影响。——罗永浩",
        "『每个人心中都有一个死小孩。』——《龙族II》",
        "『前面是山，我们就爬山；前面是海，我们就渡海；前面是皇宫，我们就开炮！』——《龙族前传》",
        "『不要习惯了黑暗就为黑暗辩护；不要为自己的苟且而得意；不要嘲讽那些比自己更勇敢热情的人们。我们可以卑微如尘土，不可扭曲如蛆虫。』——季业",
        "『若无力驾驭，自由便是负担。",
        "『若能避开猛烈的狂喜，自然不会有悲痛来袭。』  ——太宰治 《人间失格》",


    ];

    document.addEventListener('DOMContentLoaded', evt => {
        var i = Math.floor(Math.random() * subtitleList.length);
        document.querySelector('#subtitle').innerText = subtitleList[i];
    });

    //Kill XP and IE8
    (function(){
        var ua = navigator.userAgent;
        var res = /Windows NT (\d+\.\d+)/.exec(ua);
        var xpOrLower = res && JSON.parse(res[1]) < 6;
        res = /MSIE (\d+\.\d+)/.exec(ua);
        var ie8OrLower = res && JSON.parse(res[1]) < 9;
        if(xpOrLower || ie8OrLower) {
            alert('请不要用XP及之前的Windows系统，和IE8及之前的IE浏览器访问本站！');
            location.href = "about:blank";
        }
        var fromBaiduSE = /^https?:\/\/www.baidu.com/.test(document.referrer);
        if(fromBaiduSE) {
            alert('检测到你还在使用百度搜索，作为一个程序员，这是一种自暴自弃！\n\n做不作恶的程序员，从不用百度开始！');
            location.href = "about:blank";
        }
    })();
</script>
  
</div>
      </div>
      <footer id="colophon" role="contentinfo">
    <p>&copy; 2019 Suwen
    All rights reserved.</p>
    <p>Powered by <a href="http://hexo.io/" target="_blank">Hexo</a></p>
</footer>
    <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"1","bdMiniList":false,"bdPic":"","bdStyle":"2","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='/js/share.js'];</script>

<script src="/js/jquery-3.3.1.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>

<script src="/js/navigation.js"></script>

<div id="bg"></div>

  </div>
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/assets/tororo.model.json"},"display":{"position":"right","width":250,"height":400},"mobile":{"show":true},"log":false});</script></body>
</html>